Skip to content

docs: explain how to instrument an Angular 17+ app (#893) - #1011

Merged
jennifer-shehane merged 2 commits into
masterfrom
claude/code-coverage-893-triage-5tvj2g
Nov 2, 2026
Merged

jennifer-shehane merged 2 commits into
masterfrom
claude/code-coverage-893-triage-5tvj2g

Conversation

@jennifer-shehane

@jennifer-shehane jennifer-shehane commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Additional details

#893 isn't a plugin bug. The reporter's Angular app was never instrumented, so window.__coverage__ never existed and the plugin had nothing to collect. Angular CLI ignores .babelrc and babel.config.json, and since Angular 17 the default esbuild-based application builder has no hook for Istanbul. The issue has picked up a few "any solutions?" replies, so this adds an "Instrument an Angular app" subsection under "Instrument your application" in the README. It covers:

  • Why adding babel-plugin-istanbul to a Babel config does nothing in Angular
  • Installing @angular-builders/custom-webpack (matching the Angular major version), babel-loader and babel-plugin-istanbul
  • A coverage.webpack.js that runs babel-loader with istanbul as a post loader on src/**/*.ts
  • A separate coverage configuration on both the build and serve targets, so production builds stay uninstrumented. ng serve --configuration coverage fails without the matching serve entry.
  • The browser → main option rename when switching builders, and a note that Cypress config flags like env.coverage don't instrument anything

This is a README-only change, with no code changes and no new test app. A full Angular test app in the CI matrix seemed too heavy for a docs fix.

Steps to test

I checked these steps against a fresh Angular 18.2 app (ng new):

  1. With the default application builder and a .babelrc containing babel-plugin-istanbul, run ng build. The bundle contains no __coverage__, which reproduces the issue.
  2. Follow the new README section, then run ng build --configuration coverage. main.js contains the Istanbul counters. A plain development build does not.
  3. Run ng serve --configuration coverage. The served main.js is instrumented.
  4. Load the page. window.__coverage__ lists main.ts and the src/app/*.ts files, and nyc report maps results back to the TypeScript source lines, with templates included.

I've only tested Angular 18. Builder versions for 19 and later exist, but I haven't run them.

npm run build, npm test and npm run format:check pass. npm run check:markdown couldn't reach github.com from my environment, so CI is the real check for the new just-jeb/angular-builders link.

How has the user experience changed?

No change to the plugin. The README now has Angular-specific instrumentation steps.


Generated by Claude Code


Note

Low Risk
Documentation-only change with no impact on plugin behavior or build artifacts.

Overview
Adds an Instrument an Angular app subsection to the README (after the SWC section) to address users who see no window.__coverage__ because Angular never runs Istanbul through Babel or the default esbuild builder.

The new docs explain why .babelrc / babel.config.json are ignored, recommend switching build and serve to @angular-builders/custom-webpack with a post-babel-loader rule in coverage.webpack.js, and show a dedicated coverage configuration on both targets so only ng serve --configuration coverage serves instrumented bundles. It also calls out the browser → main rename and that Cypress env flags do not instrument the app.

No plugin or runtime code changes—README only, no new test app in CI.

Reviewed by Cursor Bugbot for commit a466984. Bugbot is set up for automated code reviews on this repo. Configure here.

Angular CLI ignores Babel config files, and the default esbuild-based
application builder has no hook for Istanbul, so adding
babel-plugin-istanbul to .babelrc leaves window.__coverage__ undefined.
Document switching to @angular-builders/custom-webpack with a post
babel-loader that runs istanbul, which was verified against an
Angular 18 app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ
The Angular instrumentation note left out the packages the webpack
config needs and wired instrumentation into every build. List the
install command, and scope the custom webpack config to a separate
coverage configuration on both the build and serve targets, since
ng serve --configuration coverage needs a matching serve entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUv8r5AkgdXypsb5vxyMnQ
@jennifer-shehane
jennifer-shehane merged commit 06ef988 into master Nov 2, 2026
32 checks passed
@jennifer-shehane
jennifer-shehane deleted the claude/code-coverage-893-triage-5tvj2g branch November 2, 2026 00:11
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 4.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cypress code coverage not instrumenting in angular18

2 participants